﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EntityFrameworks.Entity.Core;
using EntityFrameworks.Data.Core;
using IRepository.Core;
namespace Common.Background.BLL
{
    public abstract class BLLBase
    {
        /// <summary>
        /// 工作单元对象，由派生类通过构造方法创建对象，并对派生类公开访问
        /// </summary>
        protected IUnitOfWork UnitOfWork { get; private set; }
        /// <summary>
        /// 统一消息返回体，初始化工作放在调用它的方法里
        /// </summary>
        protected VMessage Message { get; set; }

        #region Constructors
        public BLLBase(IUnitOfWork iUnitOfWork)
        {
            UnitOfWork = iUnitOfWork;
        }
        public BLLBase()
            : this(null)
        {

        }
        #endregion

        /// <summary>
        /// 加载底层简单GURD操作
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <returns></returns>
        protected IExtensionRepository<TEntity> LoadRepository<TEntity>() where TEntity : class
        {
            return UnitOfWork == null
                ? new BackgroundBase<TEntity>()
                : new BackgroundBase<TEntity>(UnitOfWork);
        }

    }
}